<template>
  <div>
    <div >
      <table
        width="300"
        border="0"
        align="center"
        cellpadding="0"
        cellspacing="1"
        class="mars"
      >
        <tbody>
          <tr bgcolor="#fba661" height="30">
            <td width="102" height="20" bgcolor="#f3f3f3">
              <div align="center">用户名</div>
            </td>
            <td height="20" colspan="2" align="left" bgcolor="#f3f3f3">
              <div align="left">
                <input type="text" v-model="user.username" name="username" />
              </div>
            </td>
          </tr>
          <tr bgcolor="#e4f1fe">
            <td height="20" bgcolor="#f3f3f3">
              <div align="center">权限组</div>
            </td>
            <td height="20" colspan="2" align="left" bgcolor="#f3f3f3">
              <div align="left">
                <!--                          <select name="select" size="1">-->
                <!--                            <option v-model="user.gid" value="2">专家</option>-->
                <!--                            <option v-model="user.gid" value="3">单位</option>-->
                <!--                          </select>-->
                <select
                  size="1"
                  v-model="userActive"
                  @change="changeProduct($event)"
                >
                  <option
                    v-for="(item, index) in userList"
                    :key="index"
                    :value="item.id"
                  >
                    {{ item.title }}
                  </option>
                </select>
              </div>
            </td>
          </tr>
          <tr bgcolor="#e4f1fe">
            <td height="30" bgcolor="#f3f3f3">&nbsp;</td>
            <td width="60" height="30" align="left" bgcolor="#f3f3f3">
              <input
                type="submit"
                name="Submit"
                value="提交"
                @click="addUser()"
              />
            </td>
            <td width="134" height="30" align="left" bgcolor="#f3f3f3">
              <input type="reset" name="Submit2" value="取消" />
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <div id="container" >
    <div id="footer">
    <p><a href="http://www.ascenttech.com.cn/" target="_blank">版权所有：北京亚思晟商务科技有限公司 &copy;2004-2008|京ICP备05005681</a></p>
    </div>
    </div>
  </div>
</template>

<script>
export default {
    data:function() {
return {
        user:{
            uid:'',
            //默认为专家
            gid:'2',
            username:'',
            password:'1234',


        },
        userList:[{id:2,title:"专家"},{id:3,title:"单位"}],
        userActive:"2",//获取被选中的value值 默认选中的是1(管理员)

    };
},
    mounted(){

    },
    methods:{
        changeProduct(event) {
            this.userActive = event.target.value; //获取option对应的value值
            this.user.gid=this.userActive;
            console.log("你选中了",this.userActive);
            console.log(this.user);
        },
        addUser:function ()
        {
            this.$axios.post(
                "http://localhost:8080/api/admin/addUser",
                this.user
            )
                .then((resp)=>{
                    console.log(resp.data.code+" "+resp.data.msg);
                   location.href="/declare/admin/userList";
                })
        }

    }
};
</script>

<style>
@import '@/assets/css/andreas08(blue).css'
</style>